/*
 * Author: Michael Lewis <mikelikespie@gmail.com>
 * License: GPL v2 <http://www.opensource.org/licenses/gpl-license.php>
 */
#import "Message.h"

@implementation Message

static const int ROWID = 0;
static const int ADDRESS = 1;
static const int DATE = 2;
static const int TEXT = 3;
static const int FLAGS = 4;
static const int FIRST = 5;
static const int LAST = 6;

- (id) initWithStrings : (char**) strings  {
	self = [self init];
	if( self ) {
		rowid = atoi( strings[ROWID] );
		date = atoi( strings[DATE] );
		flags = atoi( strings[FLAGS] );
		if( strings[ADDRESS] ) {
			address = [[NSString alloc] initWithCString:strings[ADDRESS]];
		} else {
			address = [[NSString alloc] init];
		}
		if( strings[TEXT] ) {
			text = [[NSString alloc] initWithCString:strings[TEXT]];
		} else {
			text = [[NSString alloc] init];
		}


		fullName = [NSString alloc];

			
		if( strings[LAST] && strings[FIRST] ) {
			printf("a-\n");
			fullName = [fullName initWithFormat:@"%s, %s", strings[LAST], strings[FIRST]];
		} else if( strings[FIRST] ) {
			printf("b-\n");
			fullName = [fullName initWithCString:strings[FIRST]];
		} else if( strings[LAST] ) {
			printf("c-\n");
			fullName = [fullName initWithCString:strings[LAST]];
		} else {
			printf("d-\n");
			fullName = [fullName initWithString:address];
		}

		//NSLog(@"%@", fullName);
	}
	return self;


}

- (int) rowid {
	return rowid;
}
- (NSString*) address {
	return address;
}
- (int) date {
	return date;
}
- (NSString*) text {
	return text;
}
- (int) flags {
	return flags;
}
- (NSString*) fullName {
	return fullName;
}


@end
